﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
@* <script src="~/lib/layui/layui.js"></script> *@
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>



<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>供应商列表</title>
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-form">
            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix">
                        供应商编码
                    </div>
                    <div>
                        <input id="supplierNo" type="text" placeholder="请输入供应商编码" class="layui-input">
                    </div>

                    <div class="layui-input-prefix" style="left:50px">
                        供应商名称
                    </div>
                    <div style="left:50px">
                        <input id="supplierName" type="text" placeholder="请输入供应商名称" class="layui-input">
                    </div>

                    <div class="layui-input-prefix" style="left:100px">
                        供应商简称
                    </div>
                    <div style="left:100px">
                        <input id="supplierShort" type="text" placeholder="请输入供应商简称" class="layui-input">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:14px">
                        英文名称
                    </div>
                    <dic style="left:14px">
                        <input id="supplierEnglishName" type="text" placeholder="请输入供应商英文名称" class="layui-input">
                    </dic>

                    <div class="layui-input-prefix" style="left:77px">
                        是否启用
                    </div>
                    <div style="left:77px;width:197px">
                        <select id="supplierIsNo" lay-filter="testSelect">
                            <option value="-1">是否启用</option>
                            <option value="0">禁用</option>
                            <option value="1">启用</option>
                        </select>
                    </div>

                    <div style="left:150px">
                        <button onclick="ShowSupplier()" id="searchBtn" type="button" class="layui-btn layui-btn-normal">搜索</button>

                    </div>

                    <div style="left:170px">
                        <button onclick="Break()" type="button" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div>
                        <button type="button" class="layui-btn layui-btn-sm layui-btn-primary layui-border-blue" lay-on="test-page-custom">
                            <i class="layui-icon layui-icon-add-1">新增</i>
                        </button>
                    </div>
                </div>
            </div>

            <table style="left:320px" class="layui-table">
                <thead>
                    <tr>
                        <td><input type="checkbox" name="check" onclick="checkAll()" /></td>
                        <td>供应商编码</td>
                        <td>供应商名称</td>
                        <td>供应商简称</td>
                        <td>供应商等级</td>
                        <td>供应商评分</td>
                        <td>供应商电话</td>
                        <td>是否启用</td>
                        <td>备注</td>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
            <div id="demo-laypage-all"></div>
        </div>
    </form>
    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>

    <script>
        var $ = layui.$;
        var layer = layui.layer;
        var util = layui.util;
        var form = layui.form;
        layui.use(function () {
            // 事件
            util.on('lay-on', {
                'test-page-custom': function () {
                    layer.open({
                        type: 1,
                        area: '100%',
                        resize: false,
                        shadeClose: true,
                        title: '添加供应商',
                        content: `
                        <form class="layui-form" action="">
                            <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
                                <div class="demo-Add-container">
                                <div class="layui-form-item">
                                <div class="layui-input-group">
                                    <div class="layui-input-prefix" style="left:28px">
                                        供应商编码
                                    </div>
                                    <div style="width:400px;left:28px">
                                        <input style="width:400px" type="text" name="SupplierNo" value="" lay-verify="required" placeholder="请输入供应商编码" lay-reqtext="请填写供应商编码" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div style="left:27px">
                                        <button type="button" class="layui-btn layui-btn-primary layui-btn-xs" onclick="nodeAlls()">自动生成</button>
                                    </div>
                                </div>

                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:28px">
                                            供应商名称
                                        </div>
                                        <div style="width:500px;left:28px">
                                            <input style="width:500px" type="text" name="SupplierName" value="" lay-verify="required" placeholder="请输入供应商名称" lay-reqtext="请填写供应商名称" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:28px">
                                            供应商简称
                                        </div>
                                        <div style="width:500px;left:28px">
                                            <input style="width:500px" type="text" name="SupplierShort" value="" lay-verify="required" placeholder="请输入供应商简称" lay-reqtext="请填写供应商简称" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix">
                                            供应商英文名称
                                        </div>
                                        <input style="width:500px" type="text" name="SupplierEnglishName" value="" lay-verify="required" placeholder="请输入供应商英文名称" lay-reqtext="请填写供应商英文名称" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:28px">
                                            供应商简介
                                        </div>
                                        <div style="width:500px;left:28px">
                                            <textarea style="width:1000px" type="textarea" name="SupplierIntro" value="" lay-verify="required" placeholder="请输入内容介" lay-reqtext="请填写供应商简介" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:28px">
                                            供应商地址
                                        </div>
                                        <div style="width:500px;left:28px">
                                            <textarea style="width:1000px" type="textarea" name="SupplierAddres" value="" lay-verify="required" placeholder="请输入内容介" lay-reqtext="请填写供应商地址" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:28px">
                                            供应商等级
                                        </div>
                                        <div style="width:300px;left:28px">
                                            <select style="width:300px" name="SupplierClassName" id="supplierClassId">
                                                <option value="0">请选择</option>
                                            </select>
                                        </div>
                                        <div class="layui-input-prefix" style="left:100px">
                                            供应商评分
                                        </div>
                                        <div style="width:300px;left:100px">
                                            <input style="width:300px;" type="number" name="SupplieScore" lay-affix="number" readonly placeholder="0" class="layui-input">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix">
                                            供应商官网地址
                                        </div>
                                        <div style="width:300px">
                                            <input style="width:300px" type="text" name="SupplierOfficialAddres" value="" lay-verify="required" placeholder="请输入供应商官网地址" lay-reqtext="请填写供应商官网地址" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>

                                        <div class="layui-input-prefix">
                                            供应商邮箱地址
                                        </div>
                                        <div style="width:300px">
                                            <input style="width:300px" type="text" name="SupplierEmailAddres" value="" lay-verify="required" placeholder="请输入供应商邮箱地址" lay-reqtext="请填写供应商邮箱地址" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>

                                        <div class="layui-input-prefix" style="left:10px">
                                            供应商电话
                                        </div>
                                        <div style="width:300px;left:10px">
                                            <input style="width:300px" type="text" name="SupplierPhone" value="" lay-verify="required" placeholder="请输入供应商电话" lay-reqtext="请填写供应商电话" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:48px">
                                            联系人1
                                        </div>
                                        <div style="width:300px;left:48px">
                                            <input style="width:300px" type="text" name="SupplierOnePeople" value="" lay-verify="required" placeholder="请输入联系人1" lay-reqtext="请填写联系人1" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>

                                        <div class="layui-input-prefix" style="left:65px">
                                            联系人1-电话
                                        </div>
                                        <div style="width:300px;left:65px">
                                            <input style="width:300px" type="text" name="SupplierOnePhone" value="" lay-verify="required" placeholder="请输入联系人1-电话" lay-reqtext="请填写联系人1-电话" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>

                                        <div class="layui-input-prefix" style="left:61px">
                                            联系人1-邮箱
                                        </div>
                                        <div style="width:300px;left:61px">
                                            <input style="width:300px" type="text" name="SupplierOneEmail" value="" lay-verify="required" placeholder="请输入联系人1-邮箱" lay-reqtext="请填写联系人1-邮箱" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:48px">
                                            联系人2
                                        </div>
                                        <div style="width:300px;left:48px">
                                            <input style="width:300px" type="text" name="SupplierTwoPeople" value="" lay-verify="required" placeholder="请输入联系人2" lay-reqtext="请填写联系人2" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>

                                        <div class="layui-input-prefix" style="left:65px">
                                            联系人2-电话
                                        </div>
                                        <div style="width:300px;left:65px">
                                            <input style="width:300px" type="text" name="SupplierTwoPhone" value="" lay-verify="required" placeholder="请输入联系人2-电话" lay-reqtext="请填写联系人2-电话" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>

                                        <div class="layui-input-prefix" style="left:61px">
                                            联系人2-邮箱
                                        </div>
                                        <div style="width:300px;left:61px">
                                            <input style="width:300px" type="text" name="SupplierTwoEmail" value="" lay-verify="required" placeholder="请输入联系人2-邮箱" lay-reqtext="请填写联系人2-邮箱" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix">
                                            统一社会信用代码
                                        </div>
                                        <div style="width:285px">
                                            <input style="width:285px" type="text" name="SupplierCredit" value="" lay-verify="required" placeholder="请输入统一社会信用代码" lay-reqtext="请填写统一社会信用代码" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>

                                        <div class="layui-input-prefix" style="left:50px">
                                            是否启用
                                        </div>
                                        <div style="width:300px;left:50px">
                                            <input type="radio" name="SupplierIsNo" value="1" title="启用" lay-filter="demo-radio-filter" checked>
                                            <input type="radio" name="SupplierIsNo" value="0" lay-filter="demo-radio-filter" title="禁用">
                                        </div>

                                        <div class="layui-input-prefix" style="left:20px">
                                            供应商LOGO地址
                                        </div>
                                        <div style="width:300px;left:20px">
                                            <input style="width:300px" type="text" name="SupplierLOGO" value="" lay-verify="required" placeholder="请输入供应商LOGO地址" lay-reqtext="请填写供应商LOGO地址" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:70px">
                                            备注
                                        </div>
                                        <div style="width:500px;left:70px">
                                            <textarea style="width:1000px" type="textarea" name="SupplierRemark" value="" lay-verify="required" placeholder="请输入内容介" lay-reqtext="请填写供应商地址" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                                        </div>
                                    </div>
                                </div>


                                <div class="layui-form-item" style="left:970px">
                                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="demo-Add">新增</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                            </div>
                        </form>
                        `,
                        success: function () {
                            $(function () {
                                GenerateSupplierNo();
                                GetSuppClass();
                            })
                            function GetSuppClass() {
                                $.ajax({
                                    url: '@ViewBag.FoundationRead' + "/api/UserLi/SearchSupplierClass",
                                    data: JSON.stringify({}),
                                    type: "post",
                                    async: false,
                                    dataType: "json",
                                    contentType: "application/json",
                                    success: res => {
                                        console.log(res.data);
                                        $.each(res.data, function () {
                                            $("#supplierClassId").append(`<option value="${this.supplierClassId}">${this.supplierClassName}</option>`);
                                        });
                                        form.render('select');//重新渲染下拉框
                                    }
                                })
                            }
                            //自动生成供应商编码
                            function GenerateSupplierNo() {
                                if (('#AAA').checked== true) {
                                    var datec = new Date()
                                    var year = datec.getFullYear();
                                    var month = (datec.getMonth() + 1).toString().padStart(2, "0")
                                    var date = (datec.getDate() + 1).toString().padStart(2, "0")
                                    var hours = datec.getHours()
                                    var minute = (datec.getMinutes()).toString().padStart(2, "0")
                                    var seconds = (datec.getSeconds()).toString().padStart(2, "0")
                                    var supplierNo = "V" + year + month + date + hours + minute + seconds;
                                    ('#AAA').val(supplierNo);
                                    //重新渲染表单
                                    form.render();
                                }
                            }

                            // 对弹层中的表单进行初始化渲染
                            form.render();
                            // 表单提交事件
                            form.on('submit(demo-Add)', function (data) {
                                var field = data.field; // 获取表单字段值
                                //获取name数据
                                let first = {
                                    supplierNo: $("[name='SupplierNo']").val(),
                                    supplierName: $("[name='SupplierName']").val(),
                                    supplierShort: $("[name='SupplierShort']").val(),
                                    supplierEnglishName: $("[name='SupplierEnglishName']").val(),
                                    supplierIntro: $("[name='SupplierIntro']").val(),
                                    supplierAddres: $("[name='SupplierAddres']").val(),
                                    supplierClassId: $("[name='SupplierClassName']").val(),
                                    supplieScore: $("[name='SupplieScore']").val(),
                                    supplierOfficialAddres: $("[name='SupplierOfficialAddres']").val(),
                                    supplierEmailAddres: $("[name='SupplierEmailAddres']").val(),
                                    supplierPhone: $("[name='SupplierPhone']").val(),
                                    supplierOnePeople: $("[name='SupplierOnePeople']").val(),
                                    supplierOnePhone: $("[name='SupplierOnePhone']").val(),
                                    supplierOneEmail: $("[name='SupplierOneEmail']").val(),
                                    supplierTwoPeople: $("[name='SupplierTwoPeople']").val(),
                                    supplierTwoPhone: $("[name='SupplierTwoPhone']").val(),
                                    supplierTwoEmail: $("[name='SupplierTwoEmail']").val(),
                                    supplierCredit: $("[name='SupplierCredit']").val(),
                                    supplierIsNo: $("[name='SupplierIsNo']").val(),
                                    supplierLOGO: $("[name='SupplierLOGO']").val(),
                                    supplierRemark: $("[name='SupplierRemark']").val()
                                };
                                
                                // 显示填写结果，仅作演示用
                                // layer.alert(JSON.stringify(field), {
                                //     title: '当前填写的字段值'
                                // });
                                // 此处可执行 Ajax 等操作
                                // …
                                $.ajax({
                                    url: '@ViewBag.FoundationWrite' + "/api/UserLi/CreateSupplier",
                                    data: JSON.stringify(first),
                                    type: "post",
                                    async: true,
                                    dataType: "json",
                                    contentType: "application/json",
                                    success: res => {
                                        if (res.code > 0) {
                                            alert('新增成功');
                                            layer.closeAll(); // 关闭弹层
                                        }
                                        else {
                                            alert('新增失败');
                                        }
                                    }
                                })
                                return false; // 阻止默认 form 跳转
                            });
                            // 弹层取消事件
                            form.on('submit(demo-Break)', function (data) {
                                
                            });
                        }
                    });
                }
            })
        });
        //自动生成编码
        function nodeAlls() {
            var datec = new Date()
            var year = datec.getFullYear();
            var month = (datec.getMonth() + 1).toString().padStart(2, "0")
            var date = (datec.getDate() + 1).toString().padStart(2, "0")
            var hours = datec.getHours()
            var minute = (datec.getMinutes()).toString().padStart(2, "0")
            var seconds = (datec.getSeconds()).toString().padStart(2, "0")
            // var Encoding = "IF";
            var result = "GY" + year + month + date + hours + minute + seconds;
            console.log(result);
            $("[name='SupplierNo']").val(result);

            //重新渲染表单
            form.render();
        }
    </script>

</body>
</html>

<script>
    layui.use(['form', 'laydate', 'util'], function () {
        var form = layui.form;
        var laypage = layui.laypage;
        var layer = layui.layer;
        var $ = layui.$;
        var laydate = layui.laydate;
        var util = layui.util;

        var pageIndex = 1;
        var pageSize = 2;

        $(function (){
            ShowSupplier(pageIndex,pageSize);
        })
        // 获取供应商编码
        $('#searchBtn').click(function () {
            var supplier = $('#supplierNo').val();
            ShowSupplier(pageIndex, pageSize)
        });
        // 获取供应商名称
        $('#searchBtn').click(function () {
            var supplier1 = $('#supplierName').val();
            ShowSupplier(pageIndex, pageSize)
        });
        //供应商简称
        $('#searchBtn').click(function () {
            var supplier2 = $('#supplierShort').val();
            ShowSupplier(pageIndex, pageSize)
        });
        // 英文名称
        $('#searchBtn').click(function () {
            var supplier2 = $('#supplierEnglishName').val();
            ShowSupplier(pageIndex, pageSize)
        });
        //是否启用
        form.on('select(testSelect)', function (data) {
            ShowPermission(data.value); // data.value
        });
        //供应商管理列表
        function ShowSupplier(index,size) {
            var supplierNo = $("#supplierNo").val() || "";
            var supplierName = $("#supplierName").val() || "";
            var supplierShort = $("#supplierShort").val() || "";
            var supplierEnglishName = $("#supplierEnglishName").val() || "";
            var supplierIsNo = $("#supplierIsNo").val() || -1;
            $.ajax({
                url: '@ViewBag.FoundationRead' + "/api/UserLi/SearchSupplier",
                data: JSON.stringify({ supplierNo: supplierNo, supplierName: supplierName, supplierShort: supplierShort, supplierEnglishName: supplierEnglishName, supplierIsNo: supplierIsNo, pageIndex: index, pageSize: size }),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    var tbody = $("tbody");
                    tbody.empty();
                    if (res.data != null) {
                        $.each(res.data, function () {
                            tbody.append(`<tr>
                                <td><input type="checkbox" class="check" value="${this.supplierId}" onclick="checkfan()"/></td>
                                <td>${this.supplierNo}</td>
                                <td>${this.supplierName}</td>
                                <td>${this.supplierShort}</td>
                                <td>${this.supplierClassName}</td>
                                <td>${this.supplieScore}</td>
                                <td>${this.supplierPhone}</td>
                                <td>${this.supplierIsNo === 1 ? '启用' : '禁用'}</td>
                                <td>${this.supplierRemark}</td>
                            </tr>`);
                        });
                    }
                    form.render(); // 重新渲染下拉框
                    //完整显示
                    laypage.render({
                        elem: 'demo-laypage-all', // 元素 id
                        count: res.totalCount, // 数据总数
                        curr: index,//当前页
                        limit: size,//每页几条
                        limits: [2,3,4],
                        layout: ['count', 'prev', 'page', 'next','limit', 'refresh','skip'], // 功能布局
                        jump: function (obj, first) {
                            if (!first) {
                                ShowSupplier(obj.curr,obj.limit);
                            }
                        }
                    });
                }
            })
        }
    });

    function checkAll() {
        var check = $("[name=check]:eq(0)").prop("checked");
        $("[name=check]:gt(0)").prop("checked", check);
        console.log(check + "123321")
    }
    function checkfan() {
        var length1 = $("[name=check]:gt(0)").length
        var length2 = $("[name=check]:gt(0):checked").length
        var check = lengthl == length2;
        $("[name=check]:eq(0)").prop("checked", check)
    }

    function Break(){
        
    }

    function xuanzhe() {
        $(".fanxuan").prop("checked", $("#quanxuan").prop("checked"));
    }

    function fan() {
        var count = $(".fanxuan").length;
        var count1 = $(".fanxuan:checked").length;
        if (count == count1) {
            $("#quanxuan").prop("checked", true);
        }
        else {
            $("#quanxuan").prop("checked", false);
        }
    }
    
</script>
